package keeto.com.vn.bms.ui.adapter;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;

import keeto.com.vn.bms.model.CommentModel;
import keeto.com.vn.bms.ui.activity.CreateScheduleActivity;
import keeto.com.vn.bms.ui.activity.R;
import keeto.com.vn.bms.utils.StringUtilities;
import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class ListCommentAdapter extends ArrayAdapter<CommentModel> {
	private Context context;
	private ArrayList<CommentModel> listComment;
	private TextView tvNameComment, tvTypeName, tvTime, tvContent,tvTitle;
	
	public ListCommentAdapter(Context context, ArrayList<CommentModel> objects) {
		super(context,0,objects);
		this.context = context;
		this.listComment = objects;
	}
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View view = convertView;
		if (view == null) {
			LayoutInflater inflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
			view = inflater.inflate(R.layout.comment_adapter, parent, false);
		}
		tvTitle = (TextView) view.findViewById(R.id.title_comment);
		tvNameComment = (TextView) view.findViewById(R.id.name_comment);
		tvTypeName = (TextView) view.findViewById(R.id.typeName);
		tvTime = (TextView) view.findViewById(R.id.time_comment);
		tvContent = (TextView) view.findViewById(R.id.content_comment);
		tvNameComment.setText(StringUtilities.convertNamePeople(listComment.get(position).getFullname()));
		tvTypeName.setText(getTypeUser(listComment.get(position).getGroup_id()));
		try {
			tvTime.setText(CreateScheduleActivity.convertDateTimeHourMinuteSecond(listComment.get(position).getComment_date()));
		} catch (ParseException e) {
			e.printStackTrace();
		}
		tvTitle.setText(listComment.get(position).getTitle());
		tvContent.setText(listComment.get(position).getContent());
		return view;
	}
	private String getTypeUser(String Group_id) {
		String result = null;
		if(Group_id != null && !Group_id.equals("")){
			int GroupID = Integer.parseInt(Group_id);
			switch (GroupID) {
			case 0:
				result = "";
				break;
			case 1:
				result = "Marketing";
				break;
			case 2:
				result = context.getResources().getString(R.string.tech);
				break;
			case 3:
				result = context.getResources().getString(R.string.doctor);;
				break;
			case 4:
				result = context.getResources().getString(R.string.admin);
				break;
			case 5:
				result = context.getResources().getString(R.string.leader);
				break;

			default:
				break;
			}
		}
		return result;
		
	}

}
